$(document).ready(
    function(){
        $('input[name=category]').change(function(){
            category_value = $(this).val();
            show_subcategory_checkboxs(category_value);
        });
    }
);

/***********************************
 * Show checkboxes for subcategory
 **********************************/
function show_subcategory_checkboxs(category_value){
    if(category_value!=''){
        url = '/get/subcategory/'+category_value;
        $.getJSON(url, function(data){
            $('#select-subcategories-p').text('Subcategories: ');
            for(var key in data){
                subcategory = data[key];
                sub_input = $('<span class="subcategory-item"><input type="checkbox" name="subcategory'+subcategory+'" value="'+key+'"/>'+subcategory+'</span>');
                $('#select-subcategories-p').append(sub_input);                
            }
            $('#select-subcategories-p').css('display','block');
        });
    }else{        
        $('#select-subcategories-p').css('display','none');        
    }
}
